// Code file original author: Martin Lapierre, http://devinstinct.com

using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using EntLibContrib.Validation.Validators;

namespace EntLibContrib.Validation.Tests
{
    /// <summary>
    /// Tests <see cref="ArgumentValidation"/>.
    /// </summary>
    [TestClass]
    public class ArgumentValidationFixture
    {
        /// <summary>
        /// Tests that Validate and overloads work.
        /// </summary>
        [TestMethod]
        public void CanValidateValidArgument()
        {
            // No exception expected for all cases.
            ArgumentValidation.Validate("param", "value", new NotNullValidator());
            ArgumentValidation.Validate("param", "value", true, new NotNullValidator());
            ArgumentValidation.Validate("Invalid argument", "param", "value", true, new NotNullValidator());
        }

        /// <summary>
        /// Tests that Validate works with multiple validators.
        /// </summary>
        [TestMethod]
        public void CanValidateValidArgumentWithMultipleValidators()
        {
            ArgumentValidation.Validate("param", "value", new NotNullValidator(), new StringLengthValidator(0, RangeBoundaryType.Exclusive, int.MaxValue, RangeBoundaryType.Inclusive));
        }

        /// <summary>
        /// Tests that Validate throws an <see cref="ArgumentValidationException"/> when the argument is invalid.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentValidationException))]
        public void ValidationForInvalidArgumentThrows()
        {
            ArgumentValidation.Validate("param", null, new NotNullValidator());
        }

        /// <summary>
        /// Tests that Validate throws an <see cref="ArgumentValidationException"/> 
        /// when the argument is invalid and the exception is safe.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentValidationException))]
        public void ValidationForInvalidArgumentWithSafeExceptionThrows()
        {
            ArgumentValidation.Validate("param", null, true, new NotNullValidator());
        }

        /// <summary>
        /// Tests that Validate throws an <see cref="ArgumentValidationException"/> 
        /// when the argument is invalid and a message is specified.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentValidationException))]
        public void ValidationForInvalidArgumentWithMessageThrows()
        {
            ArgumentValidation.Validate("Invalid argument", "param", null, true, new NotNullValidator());
        }
    }
}
